<style>
    .layui-disabled, .layui-disabled:hover {
        color: #333 !important;
        cursor: not-allowed !important;
    }
</style>
<form id="menu_create" style="margin-top: 15px;" class="layui-form"
      action="{{session("guard")=='system'?route('system.menu.store'):route('admin.menu.store')}}"
      method="post">
    {{csrf_field()}}
    <div class="layui-form-item">
        <label class="layui-form-label">父栏目</label>
        <div class="layui-input-block">
            <select id="parent" name="parent" disabled style="color:#999">
                @if(is_array($parent)&&$parent["parent_id"]==0)
                    <option value="{{$parent['id']}}">{{$parent['name']}}</option>
                @else
                    <option value="{{$parent->id}}">{{$parent->name}}</option>
                @endif
            </select>
            <input style="display: none;" name="parent_id"
                   @if(is_array($parent)&&$parent["id"]>0) value="{{$parent->id}}"
                   @else value="{{$parent['id']}}" @endif />
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择守卫</label>
        <div class="layui-input-block">
            @if(session("guard")=="admin")
                <select id="type" disabled lay-verify="required">
                    {!! Code::getOptionsByCode('GUARD','admin','--请选择--') !!}
                </select>
                <input name="guard_name" value="admin" style="display: none"/>
            @else
                <select id="type" name="guard_name" lay-verify="required">
                    {!! Code::getOptionsByCode('GUARD','','--请选择--') !!}
                </select>
            @endif
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">显示图标</label>
        <div class="layui-input-block">
            <input type="text" id="icon" name="icon" autocomplete="off" placeholder="显示图标" class="layui-input">
        </div>
    </div>


    @if(session('guard')=='system')
        <div class="layui-form-item" id="link_group">
            <label class="layui-form-label" id="66666">选择路由方式</label>
            <div class="layui-input-block">
                <input type="radio" name="is_link" value="1" title="链接">
                <input type="radio" name="is_link" value="0" title="路由" checked="">
            </div>
        </div>

        <div class="layui-form-item" style="display:none;">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" id="uri_link" name="uri_link" autocomplete="off" placeholder="链接地址"
                       class="layui-input">
                <div class="layui-form-mid layui-word-aux">请以https://或http://开头</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">路由</label>
            <div class="layui-input-block">
                <input
                    onblur="admin.send('{{session("guard")=='system'?route('system.menu.check'):route('admin.menu.check')}}','GET',{'data':{'name':this.value}},0)"
                    type="text" id="uri" name="uri" autocomplete="off" placeholder="跳转路由" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">路由参数</label>
            <div class="layui-input-block">
                <textarea type="text" id="data" name="data" autocomplete="off" placeholder="路由参数" class="layui-textarea"></textarea>
                <div class="layui-text" style="color: red;font-size: 12px;width: 60%">输入路由参数，每一组一行，例：group|value(参数名称|参数值)</div>
            </div>
        </div>

    @else

        <div class="layui-form-item">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" id="uri_link" name="uri_link" autocomplete="off" placeholder="链接地址"
                       class="layui-input">
                <div class="layui-form-mid layui-word-aux">请以https://或http://开头</div>
                <input name="is_link" value="1" style="display: none;">
            </div>
        </div>
    @endif
</form>

<script type="text/javascript">
    $(function () {
        //排重
        /*$("#data").blur(function (){
            let str = $("#data").val();
            let rnArr=str.split(/[(\r\n)\r\n]+/);
            //拆分含有换行的字符串
            rnArr.forEach((item,index)=>{
                if(!item){
                   rnArr.splice(index,1);//删除空项
                }
            })
            let oldLen=rnArr.length;
            //拆分含有|的字符串
            let keys=[];
            rnArr.forEach((item)=>{
                let temp = item.split("|");
                keys.push(temp[0])
            })
            let newArr = admin.distinct(keys)
            if(oldLen!=newArr.length){
                layui.layer.msg("路由参数不可重复", {time: 2000, icon: 5});
            }
        })*/


        $("#link_group").click(function () {
            let val = $("input[name='is_link']:checked").val();
            if (val == 1) {
                $("#uri_link").parent().parent().show();
                $("#uri").parent().parent().hide();
            }
            if (val == 0) {
                $("#uri_link").parent().parent().hide();
                $("#uri").parent().parent().show();
            }
        });
    })
</script>
